<?php
include './include/common.php';
include './include/page.class.php';
if (! $_GET)
	exit ( '请不要直接访问此页面' );
$citypinyin = $_GET ['citypinyin'];
$year = $_GET['year'];
$page = isset($_GET['page']) ? $_GET['page'] : 1;

if(isset($_GET['page']))
{
	if($file = getCaches('history', $citypinyin.$year.$page))
	{
		exit('s');
		echo $file;
		exit();
	}
}
	$Area = Getone_Area_Pinyin ( $citypinyin ); //地区详情
if ($citypinyin == null)
	exit ( '参数不对' );

	Add_Hot($Area ['id'],'hots');

	$WeatherHot = Select_Hot ( 'hot',8 ); //最近关注城市
	$WeatherHots = Select_Hot ( 'hots',15 ); //最近关注城市
	
	$WeatherHott = Select_Hot ( 'hott',8 ); //最近关注城市
	
	$WeatherHotf = Select_Hot ( 'hotf',8 ); //最近关注城市
	
	$WeatherHotm = Select_Hot ( 'hotm',24 ); //最近关注城市
	
	//$rs=$db->getone("select count(*) from {$table_top}weatherlog where `AreaID`='{$Area ['id']}'");
	
	
	if ($Area ['property'] == '2') {
		$parentArea = Getone_Area_Id ( $Area ['parentid'] );
		$ppArea = Getone_Area_Id ( $parentArea ['parentid'] );
	}
	elseif ($Area ['property'] == '1' && $Area ['Level'] == '3')
	{
		$parentArea = Getone_Area_Id ( $Area ['parentid'] );
		$ppArea = Getone_Area_Id ( $parentArea ['parentid'] );
	}
	else {
		$ppArea = Getone_Area_Id ( $Area ['parentid'] );
	}
	
	$areaid = $Area['id'];
	$stdate = mktime(1,1,1,1,1,$year);
	
	$tab = getweathertable(substr($year,2,2));
		$rs = $db->getone("select count(*) as c from {$tab} where `AreaID` = '{$areaid}' and Weather not like '%null' and Weather <> '' and live <> '' ");
		if($rs["c"] ==0)
		{
			$areaid = $Area['parentid'];
			$rs=$db->getone("select count(*) as c from {$tab} where `AreaID`='{$areaid}' and Weather not like '%null%' and Weather <> '' and live <> '' ");
		}
		

	$numrows = $rs['c'];
	//var_dump("select count(*) as c from {$tab} where `AreaID`='{$areaid}' and Weather not like '%null%' and Weather <> '' and live <> '' ");
	if(isset($_GET['page']))
	{
	
		$_page = $page-1;
		$now_date = strtotime("+{$_page} month",$stdate);
		$sql_date = date('Y-m',$now_date);
		$sql_date_1 = $sql_date ."-01";
		$sql_date_2 = $sql_date . "-31";
		
		$his = $db->select("select * from {$tab} where `AreaID` = '{$areaid}' and (`Update` between '{$sql_date_1}' and '{$sql_date_2}')  and Weather not like '%null%' and Weather <> '' and live <> '' order by `Update` asc ");

		$h_page = new PageClass(12,1, $page,"/history/{$citypinyin}/y_{$year}_{page}/",$numrows);
		$page_list = $h_page->myde_write();
		foreach($his as $v){
		$v['Weather'] = str_replace ( "@", "\\", $v['Weather'] );
		$v['Weather'] = json_decode ( $v['Weather'], TRUE );
		$urldate=substr($v['Update'],0,4).substr($v['Update'],5,2).substr($v['Update'],8,2);
		$v['Weather'][2]!=$v['Weather'][6]&&$tadd="转{$v['Weather'][6]}";
		$tt=$Area['Ab'].substr($v['Update'],0,4)."年".substr($v['Update'],5,2)."月".substr($v['Update'],8,2)."日天气预报(".$v['Weather'][2].$tadd.",最高温度".$v['Weather'][1]."℃,最低温度".$v['Weather'][5]."℃)";
		$hislist.="<a href=\"/history/{$citypinyin}/{$urldate}.html\">{$tt}</a><br>";
		}
		
		
		$title=$Area['Ab']."{$year}年{$page}月全部天气预报查询";
		$keywords = $Area['Ab']."{$year}年{$page}月天气预报";
		$description = "天气啦(www.tianqi.la)实时提供{$parentArea['Ab']}{$Area[Ab]}气象局播报的{$Area[Ab]}{$year}年{$page}月份天气预报,包括提供北京地区各区县{$year}年{$page}月份的温度,降水量,湿度,风向等超准天气预报查询!";
		if (! empty ( $parentArea )) {
		$daohang = "<a href=\"/\" >天气预报查询网</a> >  <a href=\"/history/\" >全国历史天气预报</a> > <a href=\"/history/{$parentArea[pinyin]}/y_{$year}/\" >{$parentArea[Ab]}{$year}年天气预报</a> > <a href=\"/history/{$Area[pinyin]}/y_{$year}/\" >{$Area[name]}{$year}年天气预报</a> > <a href=\"/history/{$Area[pinyin]}/y_{$year}_{$page}/\" >{$Area[name]}{$year}年{$page}月天气预报</a>";
		} else {
			if (empty ( $ppArea )) {
				$daohang = "<a href=\"/\" >天气预报查询网</a> >  <a href=\"/history/\" >全国历史天气预报</a> >  <a href=\"/history/{$Area[pinyin]}/y_{$year}/\" >{$Area[name]}{$year}年天气预报</a> <a href=\"/history/{$Area[pinyin]}/y_{$year}_{$page}/\" >{$Area[name]}{$year}年{$page}月天气预报</a> ";
			} else {
			$daohang = "<a href=\"/\" >天气预报查询网</a> >  <a href=\"/history/\" >全国历史天气预报</a> > <a href=\"/history/{$Area[pinyin]}/y_{$year}/\" >{$Area[Ab]}{$year}年天气预报</a>  <a href=\"/history/{$Area[pinyin]}/y_{$year}_{$page}/\" >{$Area[name]}{$year}年{$page}月天气预报</a> ";
			}
		}
		ob_start();
		include template('hislist');
		$cnt = ob_get_contents();
		ob_end_clean();
			setCaches('history', $citypinyin.$year.$page,$cnt);
		exit($cnt);
		
	}
	else
	{
		for($i=1;$i!=13;++$i)
		{
			$str .="<li><a href='/history/{$Area[pinyin]}/y_{$year}_{$i}/'>{$Area[ab]}{$year}年{$i}月天气预报</a>";
		}
		
		

		$title=$Area['Ab']."{$year}年全部天气预报查询";
		$keywords = $Area['Ab']."{$year}年天气预报";
		$description = "天气啦(www.tianqi.la)实时提供{$parentArea['Ab']}{$Area[Ab]}气象局播报的{$Area[Ab]}{$year}年全部天气预报,包括提供北京地区各区县{$year}年全年的温度,降水量,湿度,风向等超准天气预报查询!";
		if (! empty ( $parentArea )) {
		$daohang = "<a href=\"/\" >天气预报查询网</a> >  <a href=\"/history/\" >全国历史天气预报</a> > <a href=\"/history/{$parentArea[pinyin]}/y_{$year}/\" >{$parentArea[Ab]}{$year}年天气预报</a> > <a href=\"/history/{$Area[pinyin]}/y_{$year}/\" >{$Area[name]}{$year}年天气预报</a> ";
		} else {
			if (empty ( $ppArea )) {
				$daohang = "<a href=\"/\" >天气预报查询网</a> >  <a href=\"/history/\" >全国历史天气预报</a> >  <a href=\"/history/{$Area[pinyin]}/y_{$year}/\" >{$Area[name]}{$year}年天气预报</a>  ";
			} else {
				$daohang = "<a href=\"/\" >天气预报查询网</a> >  <a href=\"/history/\" >全国历史天气预报</a> > <a href=\"/history/{$Area[pinyin]}/y_{$year}/\" >{$Area[Ab]}{$year}年天气预报</a>  ";
			}
		}
		var_dump($title,$keywords,$description,$daohang,$str);
		//echo $str;
	}

	

